<?php
/**
 * Unfuddle Message Model
 *
 * @package     Unfuddle
 * @subpackage  Data Models
 * @author      Luke Visinoni <luke.visinoni@gmail.com>
 * @copyright   (c) 2010 Luke Visinoni <luke.visinoni@gmail.com>
 * @version     $Id: Message.php 29 2011-05-09 07:08:53Z luke.visinoni $
 */
class Unfuddle_Model_Message extends Unfuddle_Model_Abstract {

    /**
     * Return collection of all messages
     */
    const URI_MESSAGES = '/messages';
    
    /**
     * Return collection of all messages for given project
     */
    const URI_PROJECT_MESSAGES = '/projects/%d/messages';
    
    /**
     * Access a message by project id and message id
     */
    const URI_PROJECT_MESSAGE_BY_ID = '/projects/%d/messages/%d';
    
    /**
     * Return collection of messages within the given category
     */
    const URI_CATEGORY_MESSAGES = '/projects/%d/categories/%d/messages';
    
    /**
     * @var string Model name
     */
    protected $_name = 'message';
    
    /**
     * @var array Model fields
     */
    protected $_fields = array (
        'author-id' => array('type' => 'integer', 'required' => false, 'read-only' => true),
        'body' => array('type' => 'text', 'required' => false, 'read-only' => false),
        'body-format' => array('type' => 'set', 'required' => false, 'read-only' => true, 'set' => array('markdown', 'textile', 'plain')),
        'body-formatted' => array('type' => 'text', 'required' => false, 'read-only' => true), // only available if formatted=true
        'created-at' => array('type' => 'datetime', 'required' => false, 'read-only' => true),
        'id' => array('type' => 'integer', 'required' => false, 'read-only' => true),
        'project-id' => array('type' => 'integer', 'required' => false, 'read-only' => true),
        'title' => array('type' => 'text', 'required' => false, 'read-only' => false),
        'updated-at' => array('type' => 'datetime', 'required' => false, 'read-only' => true),
    );
    
    /**
     * @var  array Model children
     * @todo I don't remember how these work...
     * @todo If categories are specified on UPDATE, then the existing categories
     *       will be completely replaced by the newly provided categories.
     */
    protected $_children = array('categories', 'comments', 'attachments');

}
